<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="static/css/layui.css">
</head>
<body>
<form  class="layui-form" action="">
    <div class="layui-form-item" >
        <label class="layui-form-label">username</label>
        <div class="layui-input-inline" style="margin-top: 10px">
            <input name="username" type="text" id="username"/>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">password</label>
        <div class="layui-input-inline" style="margin-top: 10px">
            <input name="password" type="password" id="password"/>
        </div>
    </div>

    <div class="layui-form-item"  width="200px" >
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="search">submit</button>
        </div>
    </div>
</form>
<script src="static/layui.js"></script>
<script>
    layui.use(['table','form'], function(){
        var table = layui.table,
            $ = layui.$,
            form = layui.form;

        form.on('submit(search)', function(data){
            console.log(data.field.username);
            console.log(data.field.password);
            $.ajax({
                url:"http://localhost:8080/doLogin",
                data: data.field,
                dataType:"json",
                xhrFields: {
                    withCredentials: true
                },
                type:"post",
                success: function(res){
                    if(res.code == 0){
                        layer.msg("登录成功");
                        setTimeout(function(){

                        },1000);
                        window.location.href="list.html";
                    }else{
                        layer.msg(res.msg);
                    }
                },
                error: function(){
                    layer.msg("服务器爆炸，请稍后再试！")
                }
            })
            return false;
        });
    });
</script>
</body>
</html>